<?xml version="1.0"?>
<OnTheFlyInstruction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <InstanceId>SP 14 Client Sample</InstanceId>
  <CustomAppConfig />
  <Tags>
    <string>CSOM Create Web</string>
  </Tags>
  <AdditionalAssemblies />
  <Code><![CDATA[// ----------------------
//  Create a web sites using CSOM, before getting a list of available templates
//
// ----------------------
  
using System;
using System.Linq;
using System.Net;
using Microsoft.SharePoint.Client;
using xSolon.Instructions;
using xSolon.Instructions.DTO;
namespace xSolon.SP.ManagedClient
{
    public class SP14Client_Sample : AbstractInstruction
    {
        public override void Run()
        {
            SP14ClientHelper instr = new SP14ClientHelper();

            NetworkCredential creds = null;

            creds = new NetworkCredential("", "", "");

            var ctx = instr.GetContext("http://localhost",
                SP14AuthenticationType.Windows, creds);
            Script(ctx, instr);
        }

        void Script(ClientContext ctx, SP14ClientHelper instr)
        {
            ctx.Load(ctx.Web);

			WebTemplateCollection temps = ctx.Web.GetAvailableWebTemplates(1033,true);
			
			ctx.Load(temps);
			
			ctx.ExecuteQuery();

            NotifyInformation(temps.Count.ToString());
            
            temps.ToList().ForEach(i =>{
            	NotifyInformation(i.Name);
            });
            
            
            string blogDescription = "";
            int blogLanguage = 1033;
            string blogTitle = "test2";
            string blogUrl = "test2";
            bool blogPermissions = false;
            string webTemplate = "STS#1";
            
            WebCreationInformation webCreateInfo = new WebCreationInformation();
            webCreateInfo.Description = blogDescription;
            webCreateInfo.Language = blogLanguage;
            webCreateInfo.Title = blogTitle;
            webCreateInfo.Url = blogUrl;
            webCreateInfo.UseSamePermissionsAsParentSite = blogPermissions;
            webCreateInfo.WebTemplate = webTemplate;

            Web oNewWebsite = ctx.Web.Webs.Add(webCreateInfo);

            ctx.Load(
                oNewWebsite,
                website => website.ServerRelativeUrl,
                website => website.Created);

            
            ctx.ExecuteQuery();

            NotifyInformation("Server-relative Url: {0} Created: {1}", oNewWebsite.ServerRelativeUrl, oNewWebsite.Created);

        }

    }
}]]></Code>
</OnTheFlyInstruction>